<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>直航转关互转</title>
    <jsp:include page="../../head.jsp"/>
</head>
<script type="text/javascript">
    var id = location.hash.substr(1).split("&")[0];
    var isSignWS = location.hash.substr(1).split("&")[1];
    var formSetting = {
        title: "直航转关互转",
        module: "save",
        numCount: "1",
        columns: [{
            name: "id",
            label: "id",
            hidden: true
        }, {
            name: "data_type",
            label: "转关类型",
            type: "dropdown",
            data: [["直航", "直航"], ["转关", "转关"]],
            op: "eq",
            minLength: 0
        }, {
            name: "ship_name",
            label: "船名"
        }, {
            name: "ship_code",
            label: "船舶代码"
        }, {
            name: "export_port",
            label: "出口口岸"
        }, {
            name: "voyage_no",
            label: "航次号"
        }, {
            name: "bl_no",
            label: "提运单号"
        }, {
            name: "transport_na",
            label: "运输工具名称"
        }],
        form: {
            'url': 'bi-doZhuanGuan?id=' + id,
            'data': function () {
                if (id) {
                    var dataValue = "";
                    $.ajax({
                               url: "declaration-find?id=" + id + "&isSignWS=" + isSignWS,
                               async: false,
                               cache: false,
                               success: function (data) {
                                   if (isSignWS == 'true') {
                                       if (data.bl_no != '') {
                                           if (data.data_type != '直航') {
                                               layer.msg("直航转关类型数据不一致，请核查！");
                                           }
                                           data.data_type = '直航';
                                       } else {
                                           if (data.data_type != '转关') {
                                               layer.msg("直航转关类型数据不一致，请核查！");
                                           }
                                           data.data_type = '转关';
                                       }
                                   }
                                   if (data.data_type != "转关") {
                                       /*if(isSignWS && (!data.ship_name || !data.ship_code || !data.export_port || !data.transport_na)){
                                           layer.msg("获取数据失败");
                                       }*/
                                       setTimeout(function () {
//                                           form_in_control_2.parentElement.innerHTML += "转关";
//                                           form_in_control_2.style.display = "none";
                                           form_in_control_3.value =
                                               data.ship_name != null ? data.ship_name : "";//"船名";
                                           form_in_control_4.value =
                                               data.ship_code != null ? data.ship_code : "";//"船舶代码";
                                           form_in_control_5.value =
                                               data.export_port != null ? data.export_port : "";//"出口口岸";
                                           form_in_control_6.parentElement.parentElement.style.display =
                                               "none";//航次号
                                           form_in_control_7.parentElement.parentElement.style.display =
                                               "none";//提运单号
                                           form_in_control_8.value =
                                               data.transport_na != null ? data.transport_na : "";//"运输工具名称";
                                           $(toZhuanGuanForm).show();
                                       }, 100)
                                   }
                                   else {
                                       /*if(isSignWS && (!data.voyage_no || !data.bl_no || !data.transport_na)){
                                           layer.msg("获取数据失败");
                                       }*/
                                       setTimeout(function () {
//                                           form_in_control_2.parentElement.innerHTML += "直航";
//                                           form_in_control_2.style.display = "none";
                                           form_in_control_3.parentElement.parentElement.style.display =
                                               "";//船名
                                           form_in_control_4.parentElement.parentElement.style.display =
                                               "none";//船舶代码
                                           form_in_control_5.parentElement.parentElement.style.display =
                                               "none";//出口口岸
                                           form_in_control_6.value =
                                               data.voyage_no != null ? data.voyage_no : "";//航次号
                                           form_in_control_7.value =
                                               data.bl_no != null ? data.bl_no : "";//提运单号
                                           form_in_control_8.value =
                                               data.transport_na != null ? data.transport_na : "";//"运输工具名称";
                                           $(toZhuanGuanForm).show();
                                       }, 100)
                                   }

                                   data.data_type = (data.data_type == "转关" ? "直航" : "转关");
                                   dataValue = data;
                               }
                           });
                    return dataValue;
                } else {
                    return null;
                }
            },
            'ajaxForm': {
                success: function (result) {
                    if (result) {
                        var msg = JSON.parse(result.msg);
                        if (msg.state) {
                            jw.alert(msg.msg, {
                                onOk: function () {
                                    try {
                                        jw.close();
                                        parent.layer.closeAll();
                                    } catch (err) {
                                    }
                                }
                            });
                        }
                        else {
                            jw.alert(msg.msg);
                        }
                    } else {
                        jw.alert("服务器通讯失败。");
                    }
                }
            }
// 			'afterAjaxSuccess' : function(responseText, statusText, xhr, $form) {
// 				var state = $.parseJSON(responseText.msg).state;
// 				if(state=="1") {
// 					try{jw.close();}catch(err){}
// 				}
// 			}
        },
        buttons: {
            custom: [
                {
                    id: "saveAndUploadBtn",
                    value: "保存并同步QP",
                    click: function () {
                        $("#saveButton").click();
                        $.ajax({
                                   type: "post",
                                   cache: false,
                                   url: "declaration-syncQPData.do?did=" + id + "&fu=0",
                                   dataType: "json",
                                   success: function (result) {
//                                       alert(result.msg);
                                   }
                               });
                    }
                }
            ]
        }
    };
    $(document).ready(function () {
        $("#toZhuanGuanForm").mrdForm(formSetting);
        $("input[name='control_data_type_dropdown']").blur(function () {
            if ($(this).val() == "直航") {
                form_in_control_3.parentElement.parentElement.style.display =
                    "";
                form_in_control_4.parentElement.parentElement.style.display =
                    "none";
                form_in_control_5.parentElement.parentElement.style.display =
                    "none";

                form_in_control_6.parentElement.parentElement.style.display =
                    "";
                form_in_control_7.parentElement.parentElement.style.display =
                    "";
            } else {
                form_in_control_3.parentElement.parentElement.style.display =
                    "";
                form_in_control_4.parentElement.parentElement.style.display =
                    "";
                form_in_control_5.parentElement.parentElement.style.display =
                    "";
                form_in_control_6.parentElement.parentElement.style.display =
                    "none";
                form_in_control_7.parentElement.parentElement.style.display =
                    "none";
            }
        });
    });
    window.onbeforeunload = function (e) {
        if (id) {
            $.ajax({
                       url: '/datalock/onUnlock.do?opaId=VDBS&bidId=' + id,
                       async: false
                   });
        }
    };
    window.onunload = function (e) {
        if (id) {
            $.ajax({
                       url: '/datalock/onUnlock.do?opaId=VDBS&bidId=' + id,
                       async: false
                   });
        }
    };
</script>
<body style="height:500px;">
<div style="width: 100%">
    <div id="toZhuanGuanForm" style="display:none"></div>
</div>
</body>
</html>
